import { Redirect, Route, Switch } from 'react-router-dom';
import NotFound from '@/views/NotFound';
import PrivateRoute from '@/routes/PrivateRoute';

import Dashboard from "@/views/Dashboard";
import JobList from '@/views/JobList'
import JobAdd from '@/views/JobAdd'
import JobEdit from '@/views/JobEdit'
import Profile from '@/views/Profile'

const MainList = [
    { path: "/dashboard", key: "dashboard", title: "Dashboard", component: <Dashboard/> },
    { path: "/jobs", key: "jobs", title: "All Jobs", component: <JobList/> },
    { path: "/jobAdd",  key: "jobAdd", title: "Add Job", component: <JobAdd/> },
    { path: "/jobEdit/:id",  key: "jobEdit", title: "Update Job", component: <JobEdit/> },
    { path: "/profile", key: "profile", title: "Profile", component: <Profile/> },
];

const MainRoutes = () => {
   return (
      <Switch>
         <Route exact path="/" key="redirect">
            <Redirect to="/dashboard" />
         </Route>
         {MainList.map((item) => (
            <PrivateRoute path={item.path} key={item.key}>
               {item.component}
            </PrivateRoute>
         ))}
         <Route key="not-found">
            <NotFound />
         </Route>
      </Switch>
   );
};

export default MainRoutes;
